<?php
/**
 * スコア選択コントローラマッパー
 */
require_once 'Request/Request.php';
require_once APPLICATION_PATH . '/models/Score/xml/ScoreXmlController.php';

/**
 * スコア選択コントローラマッパークラス
 * @author admin
 *
 */
class Components_ScoreSelect_Mapper extends Models_Score_Xml_Controller
{
	const MIN = 0;
	const MAX = 20;

	public function save()
	{
		if ( !$this->_valid() ) {
			return FALSE;
		}

		$this->clear();
		$this->saveToFile(
				$_REQUEST[HttpRequest::FIRST_HALF_POINT],
				$_REQUEST[HttpRequest::FIRST_HALF_LOST],
				$_REQUEST[HttpRequest::SECOND_HALF_POINT],
				$_REQUEST[HttpRequest::SECOND_HALF_LOST]);
		
		return TRUE;
	}

	protected function _valid()
	{
		$objRequest = new Lib_Request();
		$objRequest->ValidNumericList
		= array(
				HttpRequest::FIRST_HALF_POINT,
				HttpRequest::FIRST_HALF_LOST,
				HttpRequest::SECOND_HALF_POINT,
				HttpRequest::SECOND_HALF_LOST);
		$objRequest->ValidRequireList
		= array(
				HttpRequest::FIRST_HALF_POINT,
				HttpRequest::FIRST_HALF_LOST,
				HttpRequest::SECOND_HALF_POINT,
				HttpRequest::SECOND_HALF_LOST
		);
		if (!$objRequest->valid()){
			return FALSE;
		}

		if (($objRequest->get(HttpRequest::FIRST_HALF_POINT) < self::MIN) OR ($objRequest->get(HttpRequest::FIRST_HALF_POINT) > self::MAX)){
			return FALSE;
		}
			if (($objRequest->get(HttpRequest::FIRST_HALF_LOST) < self::MIN) OR ($objRequest->get(HttpRequest::FIRST_HALF_LOST) > self::MAX)){
			return FALSE;
		}
		if (($objRequest->get(HttpRequest::SECOND_HALF_POINT) < self::MIN) OR ($objRequest->get(HttpRequest::SECOND_HALF_POINT) > self::MAX)){
			return FALSE;
		}
		if (($objRequest->get(HttpRequest::SECOND_HALF_LOST) < self::MIN) OR ($objRequest->get(HttpRequest::SECOND_HALF_LOST) > self::MAX)){
			return FALSE;
		}

		return TRUE;
	}
}